package com.example.springboot_demo.order;

/**
 * @BelongsProject: springboot_demo
 * @BelongsPackage: com.example.springboot_demo.order
 * @Author: 江岸
 * @CreateTime: 2021-06-06 23:29
 * @Description:
 */
public class Context {
    private ProductOrder order;
    private AbstractSate state;

    public Context(ProductOrder order){
        this.order = order;
        String status = order.getStatus();
        AbstractSate stateClassByName = ActionEnum.getStateClassByName(status);
        stateClassByName.context = this;
        this.state = stateClassByName;
    }

    public Context(AbstractSate state) {
        this.state = state;
    }

    public void fun(){
        this.state.fun();
    }

    public AbstractSate getState() {
        return state;
    }

    public void setState(AbstractSate state) {
        this.state = state;
        this.order.setStatus(state.getName());
    }

    public ProductOrder getOrder() {
        return order;
    }

    public void setOrder(ProductOrder order) {
        this.order = order;
    }
}
